package edu.xust.dao.impl;

import edu.xust.config.Repository;
import edu.xust.config.Resource;
import edu.xust.dao.StationDao;
import edu.xust.entity.Station;
import edu.xust.entity.StationExample;
import edu.xust.mapper.StationMapper;
import edu.xust.page.PageInfo;

import java.util.List;

/**
 * @auther: zhangxin
 * @Description:
 */
@Repository("stationDao")
public class StationDaoImpl implements StationDao {

    @Resource
    StationMapper stationMapper;

    @Override
    public List<Station> getStationByPage(PageInfo pageInfo) throws Exception {
        StationExample stationExample = new StationExample();
        long l = stationMapper.countByExample(null);
        pageInfo.setItemCount((int)l);
        stationExample.setOffset(pageInfo.getOffset());
        stationExample.setLimit(pageInfo.getPageSize());
        return stationMapper.selectByExample(stationExample);
    }

    @Override
    public List<Station> selectByExample(StationExample example) {
        return stationMapper.selectByExample(example);
    }

    @Override
    public Integer addStation(Station station) {
        return stationMapper.insert(station);
    }

    @Override
    public Integer editStation(Station station) {
        return stationMapper.updateByPrimaryKey(station);
    }

    @Override
    public Station getStationById(String sid) {
        return stationMapper.selectByPrimaryKey(sid);
    }

    @Override
    public Integer deleteStationById(String sid) {
        return stationMapper.deleteByPrimaryKey(sid);
    }

}
